package br.com.portalnet.tools;

import org.apache.commons.mail.*;



public class EmailUtils {
	
	 private static final String HOSTNAME = "smtp.gmail.com";	
	  private static final String USERNAME = "otavioasilverio@gmail.com";	
	  private static final String PASSWORD = "kayot9128";	
	  private static final String EMAILORIGEM = "otavioasilverio@gmail.com";
	 
	
	  public static Email conectaEmail() throws EmailException
	  {	
		  Email email = new SimpleEmail();	 
		  email.setHostName(HOSTNAME);	
		  email.setSmtpPort(587);
		  email.setAuthentication(USERNAME, PASSWORD); 
		  email.setTLS(true);	
		  email.setFrom(EMAILORIGEM);	
		  return email;
	 
	  }
	
	  
	
	  public static void enviaEmail( String destino, String titulo, String mensagem) throws EmailException
	  {
		  
		  
		  try
		  {
		  
		  SimpleEmail email = new SimpleEmail();  
	        email.setHostName(HOSTNAME);  
	        email.setAuthentication(USERNAME, PASSWORD);  
	        email.setSSL(true);  
	        email.addTo(destino);  
	        email.setFrom(EMAILORIGEM);  
	        email.setSubject(titulo);  
	        email.setMsg(mensagem);  
	        email.send();  
	        email = null; 
	
	        
		  }
		  catch(Exception e)
		  {
			  System.out.println("Email error : "+e);
		  }
	        
		/*  Email email = new SimpleEmail();	
		  //email = conectaEmail();
		  email.setHostName(HOSTNAME);	
		  email.setSmtpPort(587);
		  email.setAuthentication(USERNAME, PASSWORD); 
		  email.setTLS(true);	
		  email.setFrom(EMAILORIGEM);
		  email.setSubject(titulo);	
		  email.setMsg(mensagem);	
		  email.addTo(destino);
		  String resposta = email.send();  
		  Mensagens msg = new Mensagens();	  
		  msg.mensagemGrowl("informacao", "is we" ,"that fly!!!!!" );*/
	
	  }


}
